package cn.circle.system.dao.impl;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import cn.circle.commom.dao.impl.BaseDaoImpl;
import cn.circle.system.dao.ISysLostAndFoundDao;
import com.graduation.system.model.SysCustomer;
import com.graduation.system.model.SysLostAndFound;



/**
* 具体实现SysCustomer的CRUD
* 作者：
* 日期：
* 
* */
@Repository
public class SysLostAndFoundDaoImpl  extends BaseDaoImpl<SysLostAndFound> implements ISysLostAndFoundDao {
	@SuppressWarnings("unchecked")
	public List<SysLostAndFound> datagrid() {
		// TODO Auto-generated method stub
		String hql = "from SysLostAndFound  ";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		return query.list();
	}
	
	public boolean updateAll(SysLostAndFound c) {
		
		StringBuffer hql = new StringBuffer(
				"update SysLostAndFound s set ");
		
		//拼接修改条件
		if(c.getArcitleName() != null && !"".equals(c.getArcitleName())){
			hql.append("  s.arcitleName = '"+c.getArcitleName()+"' ");
		}
		if(c.getIteminform() != null && !"".equals(c.getIteminform())){
			hql.append(" , s.iteminform = '"+c.getIteminform()+"' ");
		}
		if(c.getContactPerson() != null && !"".equals(c.getContactPerson())){
			hql.append(" , s.contactPerson = '"+c.getContactPerson()+"' ");
		}
		if(c.getContactPhone() != null && !"".equals(c.getContactPhone())){
			hql.append(" , s.contactPhone = '"+c.getContactPhone()+"' ");
		}
		if(c.getSysDepartment().getDepId() != null && !"".equals(c.getSysDepartment().getDepId())){
			hql.append(" , s.sysDepartment.depId = "+c.getSysDepartment().getDepId()+" ");
		}
		if(c.getLafIcon() != null && !"".equals(c.getLafIcon())){
			hql.append(" , s.lafIcon = '"+c.getLafIcon()+"' ");
		}
		if(!"".equals(c.getStatus())){
			hql.append(" , s.status = '"+c.getStatus()+"' ");
		}
		if(!"".equals(c.getMark())){
			hql.append(" , s.mark = '"+c.getMark()+"' ");
		}
		
		
		
	
		hql.append(" where s.arcitleId ="+c.getArcitleId()+" ");
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql.toString());
		return (query.executeUpdate() > 0);
	}
	
	public boolean deleteAll(String ids) {
		String hql = "delete SysLostAndFound  where arcitleId in ("+ids+") ";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		//query.setString(0, ids);
		return (query.executeUpdate() > 0);
		}
	
	public boolean removeAll(String ids) {
		String hql = "update SysLostAndFound  set status = 0 where arcitleId in ("+ids+") ";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		return (query.executeUpdate() > 0);
	}

}
